import router from '@system.router';
export default {
    data:{
        patternText:'',
        carr:[],
        isThree:false,
        tem:0,
        hour:0,
        min:0,
        sec:0,
        timer:'',
        isPause:false,
        pauseImg:"/common/images/pause2.png",
        startImg:"/common/images/start2.png",
        nowSec:0,
        recipeName:'',
    },
    computed:{
        statusText(){
            if(this.patternText=="蒸"||this.patternText=="烤"){
                return "烹饪中";
            }
            else{
                return this.patternText+'中';
            }
        },
        showHour(){
            if(this.hour<10){
                return '0'+this.hour;
            }
            else{
                return ''+this.hour;
            }
        },
        showMin(){
            if(this.min<10){
                return '0'+this.min;
            }
            else{
                return ''+this.min;
            }
        },
        showSec(){
            if(this.sec<10){
                return '0'+this.sec;
            }
            else{
                return ''+this.sec;
            }
        },
//        展示总的时间（不变）
        showTime(){
            let str='';
//            hour
            if(this.isThree){
                if(this.carr[1]<10){
                    str+='0'+this.carr[1];
                }
                else{
                    str+=''+this.carr[1];
                }

            }
            else{
                if(this.carr[0]<10){
                    str+='0'+this.carr[0];
                }
                else{
                    str+=''+this.carr[0];
                }
            }
            str+=':';
//            min
            if(this.isThree){
                if(this.carr[2]<10){
                    str+='0'+this.carr[2];
                }
                else{
                    str+=''+this.carr[2];
                }

            }
            else{
                if(this.carr[1]<10){
                    str+='0'+this.carr[1];
                }
                else{
                    str+=''+this.carr[1];
                }
            }
            str+=':';
//            sec
            str+="00";


            return str;
        },
        cTem(){
            if(this.isThree){
                return this.carr[0]+'℃';
            }
            else{
                return "无";
            }
        },
        allSec(){
            if(this.isThree){
                return this.carr[1]*60*60+this.carr[2]*60+this.sec;
            }
            else{
                return this.carr[0]*60*60+this.carr[1]*60+this.sec;
            }

        },
        per(){
//            return (this.nowSec/this.allSec)*100;
//            let all=this.allSec
            return (this.nowSec/this.allSec)*100;
//           return  this.allSec()/100;
        }

    },
    onInit(){
        this.patternText=this.status;
        this.carr=this.arr;
        this.recipeName=this.rname;
        if(this.arr.length==3){
            this.isThree=true;
            this.tem=this.arr[0];
            this.hour=this.arr[1];
            this.min=this.arr[2];
        }
        else{
            this.isThree=false;
            this.tem='';
            this.hour=this.arr[0];
            this.min=this.arr[1];
        }
//        console.info();
/*        console.info(this.arr);
        console.info(this.hour);
        console.info(this.min);*/

//        倒计时
        let that=this;
        this.timer=setInterval(function(){
            if(that.sec==0&&that.min>0){
                that.min--;
                that.sec=60;
            }
            else if(that.sec==0&&that.min==0&&that.hour>0){
                that.hour--;
                that.min=59;
                that.sec=60;
            }
            if(that.sec>0){
                that.sec--;
                that.nowSec++;
            }
        },1000);
    },
    stopClick(){
        clearInterval(this.timer);
        this.hour=0;
        this.min=0;
        this.sec=0;
        this.nowSec=0;
    },
    pauseClick(){
        this.isPause=!this.isPause;
        if (this.isPause) {
            clearInterval(this.timer);
        }else{
            let that=this;
            this.timer=setInterval(function(){
                if(that.sec==0&&that.min>0){
                    that.min--;
                    that.sec=60;
                }
                else if(that.sec==0&&that.min==0&&that.hour>0){
                    that.hour--;
                    that.min=59;
                    that.sec=60;
                }
                if(that.sec>0){
                    that.sec--;
                    that.nowSec++;
                }
            },1000);
        }
    },
    leftClick(){
        router.back();
    }
}